package com.example.zhc36.fragment.apadter;

import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

public class Paadapter extends PagerAdapter {
    private int[] img;

    @Override
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    public Paadapter(int[] img) {
        this.img = img;
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view==object;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        ImageView imgs=new ImageView(container.getContext());//获得上下文
        int i = position % img.length;


        imgs.setImageResource(img[i]);//把图片放入到page中
        container.addView(imgs);
        imgs.setScaleType(ImageView.ScaleType.CENTER_CROP);
        return imgs;


    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
     container.removeView((View) object);
    }
}
